package cn.fl.institution.controller;

import cmm.mid.core.framework.dto.DataResultDTO;
import cmm.mid.core.framework.page.DataResultVO;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.commons.result.ResponseData;
import cn.fl.customer.service.ICstBscInfoService;
import cn.fl.customer.vo.CstBscInfoVO;
import cn.fl.customer.vo.CstCorpBscInfoVO;
import cn.fl.customer.vo.CstCorpTeamVO;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.framework.constant.DictionaryConstant;
import cn.fl.preloan.dto.financialinterface.PreCreditApplyRequest;
import cn.fl.preloan.dto.financialinterface.PreCreditApplyResponseDTO;
import cn.fl.preloan.enums.PreCreditStatusEnum;
import cn.fl.preloan.financialinterface.IFinancialService;
import cn.fl.project.condition.PrjCstAccInfoQueryCondition;
import cn.fl.project.service.IPrjBscInfoService;
import cn.fl.project.service.IPrjCstAccInfoService;
import cn.fl.project.vo.PrjBscInfoVO;
import cn.fl.project.vo.PrjCstAccInfoVO;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import pay.business.facade.custpay.api.IBankCardApiService;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @Description: 项目基础信息表 控制层 建设银行
 */
@Controller
@RequestMapping("/institution/ccbanktb")
public class PrjBscInfoInsCcbanktbController {

    @Autowired
    private IPrjCstAccInfoService prjCstAccInfoService;

    @Autowired
    private IBankCardApiService bankCardApiService;

    @Autowired
    private IFinancialService financialService;

    @Autowired
    private IPrjBscInfoService prjBscInfoService;

    @Autowired
    private ICstBscInfoService cstBscInfoService;

    /**
     * 建行准入
     */
    @RequestMapping(value = "/submitCredit.do", method = RequestMethod.GET)
    @ResponseBody
    public DataResultVO submitCredit(HttpServletRequest request) throws BaseException {
        BaseLogUtils.newLogger("submitCredit.建行准入：" + JSON.toJSONString(request.getParameterMap()) + "，操作人：" + CurrentThreadContext.getCurrentUserName()).info();
        String prjId = request.getParameter("prjId");
        String cstId = request.getParameter("cstId");
        String bcCertTypCd = request.getParameter("bcCertTypCd");//补充证件类型：组织机构代码||统一社会信用代码
        String bcCertNo = request.getParameter("bcCertNo");//补充证件号
        String cstAccInfoId = request.getParameter("cstAccInfoId");//客户账户信息id
        String accTypCd = request.getParameter("accTypCd");
        String accNo = request.getParameter("accNo");//银行账户
        CstBscInfoVO cstBscInfoVO = cstBscInfoService.selectDetailById(Long.valueOf(cstId));
        PrjCstAccInfoQueryCondition prjcstAccInfo = getRequestParamForAcc(request);

        //入参校验
        if ("b".equals(cstBscInfoVO.getCertTypCd())) {
            if (StringUtils.isEmpty(bcCertTypCd)) {
                throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "证件类型为空!");
            }
            if (StringUtils.isEmpty(bcCertNo)) {
                throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "证件号为空!");
            }
        }
        DataResultVO dataResultVO = new DataResultVO(BaseConstant.IS_YESNO_YES, "准入成功!");
        Long id = null;
        try {
            PrjBscInfoVO prjBscInfoVO = prjBscInfoService.selectById(Long.valueOf(prjId));
            //1.保存客户账户信息
            PrjCstAccInfoVO vo = new PrjCstAccInfoVO();
            vo.setPrjId(Long.valueOf(prjId));
            vo.setCstId(prjcstAccInfo.getCstId());
            vo.setInsCode(prjcstAccInfo.getInsCode());
            vo.setIsDel(0);
            vo.setCstNm(cstBscInfoVO.getCstNm());
            if (StringUtils.isNotEmpty(bcCertTypCd)) {
                vo.setCertTypCd(bcCertTypCd);
            }
            if (StringUtils.isNotEmpty(bcCertNo)) {
                vo.setCertNo(bcCertNo);
            }
            if (StringUtils.isEmpty(cstAccInfoId)) {
                Long add = prjCstAccInfoService.add(vo);
                BaseLogUtils.newLogger("submitCredit.建行准入,新增客户账户信息：" + JSON.toJSONString(vo) + "，result：" + add).info();
                prjcstAccInfo.setId(add);
                vo.setId(add);
                id = add;
                dataResultVO.setData(add);
            } else {
                prjcstAccInfo.setId(Long.valueOf(cstAccInfoId));
                vo.setId(Long.valueOf(cstAccInfoId));
                boolean modify = prjCstAccInfoService.modify(vo);
                BaseLogUtils.newLogger("submitCredit.建行准入,修改客户账户信息：" + JSON.toJSONString(vo) + "，result：" + modify).info();
            }
            //2.若为城配业务，校验卡bin、四要素
            if (null != prjBscInfoVO && "CPYW".equals(prjBscInfoVO.getPrjTypCd())) {
                String chkBinCd = "0";//卡bin结果
                String chkRstCd = "0";//四要素结果
                String rstDesc = null;//四要素结果描述
                if (StringUtils.isEmpty(accTypCd)) {
                    return new DataResultVO(BaseConstant.IS_YESNO_NO, "账户类型为空");
                }
                if (StringUtils.isEmpty(accNo)) {
                    return new DataResultVO(BaseConstant.IS_YESNO_NO, "银行账号为空");
                }
                // 当账户类型为个人时，校验卡bin和四要素：法人姓名，法人身份证号，银行卡号
                if (accTypCd.equals("0200")) {
                    //卡bin
                    PrjCstAccInfoVO infoVO = prjCstAccInfoService.selectById(prjcstAccInfo.getId());
                    if (!(BaseConstant.IS_YESNO_YES_STR.equals(infoVO.getChkBinCd()) && StringUtils.isNotEmpty(infoVO.getAccNo()) && accNo.equals(infoVO.getAccNo()))){
                        BaseLogUtils.newLogger("submitCredit.校验银行卡号START,accNo:" + accNo.trim()).info();
                        DataResultDTO dataResultDTO = this.bankCardApiService.searchCardBin(accNo.trim());
                        BaseLogUtils.newLogger("submitCredit.校验银行卡号END,accNo:" + accNo.trim() + ",dataResultDTO" + JSON.toJSONString(dataResultDTO)).info();
                        if (null != dataResultDTO && dataResultDTO.getSuccess() == 1 && null != dataResultDTO.getData()){
                            Object data = dataResultDTO.getData();
                            JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(data));
                            String bankCd = jsonObject.getString("bankCd");
                            String cardType = jsonObject.getString("cardType");
                            if ("CCB".equals(bankCd) && BaseConstant.IS_YESNO_NO_STR.equals(cardType)){
                                chkBinCd = "1";
                            }
                        }
                    } else {
                        chkBinCd = "1";
                    }
                    //四要素
                    DataResultVO resultVO = prjCstAccInfoService.snVerifyModifyPrjAccInfo(prjcstAccInfo);
                    BaseLogUtils.newLogger("submitCredit.校验四要素END,prjcstAccInfo:" + JSONObject.toJSONString(prjcstAccInfo) + ",dataResultVO" + JSON.toJSONString(resultVO)).info();
                    if (BaseConstant.IS_YESNO_YES == resultVO.getSuccess() && null != resultVO.getData()) {
                        Map<String, String> resultMap = (Map<String, String>) resultVO.getData();
                        chkRstCd = resultMap.get("chkRstCd");
                        rstDesc = resultMap.get("rstDesc");
                    }
                    //将卡bin校验结果及四要素校验结果存入
                    vo.setChkBinCd(chkBinCd);
                    vo.setChkRstCd(chkRstCd);
                    vo.setRstDesc(rstDesc);
                } else {
                    vo.setChkBinCd("0");
                    vo.setChkRstCd("0");
                    vo.setRstDesc("对公账户无需校验四要素");
                }
                //对公直接保存
                vo.setMp(prjcstAccInfo.getMp());
                vo.setBkCd("01");
                vo.setBkNm("建设银行");
                vo.setAccNo(accNo.trim());
                vo.setAccTypCd(accTypCd);
                boolean modify1 = prjCstAccInfoService.modify(vo);
                BaseLogUtils.newLogger("savePrjCstAccInfo.修改建行对公账户数据vo=" + JSON.toJSONString(vo) + "response:" + modify1).info();

                //个人账户，卡bin和四要素校验失败需提示，不再调用准入，成功才调用准入
                if (accTypCd.equals("0200") && chkBinCd.equals("0")){
                    dataResultVO.setSuccess(0);
                    dataResultVO.setInfo("卡bin校验失败，需为建行借记卡，请核实！");
                    return dataResultVO;
                }
                if (accTypCd.equals("0200") && chkRstCd.equals("0")){
                    dataResultVO.setSuccess(0);
                    dataResultVO.setInfo("四要素校验失败，原因：" + rstDesc);
                    return dataResultVO;
                }
            }
            //3.建行准入 --- 预授信接口
            CstCorpBscInfoVO cstCorpBscInfoVO = cstBscInfoVO.getCstCorpBscInfoVO();
            CstCorpTeamVO cstCorpTeamVO = cstBscInfoVO.getCstCorpBscInfoVO().getCstCorpTeamVO();
            PreCreditApplyRequest preCreditApplyRequest = new PreCreditApplyRequest();
            preCreditApplyRequest.setBizSN(prjId);
            preCreditApplyRequest.setInsCode(prjcstAccInfo.getInsCode());
            preCreditApplyRequest.setIdCardNo(cstCorpTeamVO.getCertNo());
            preCreditApplyRequest.setMobilePhone(cstCorpTeamVO.getMp1());
            preCreditApplyRequest.setLegalPersonName(cstCorpTeamVO.getmNm());
            preCreditApplyRequest.setCustomerName(cstBscInfoVO.getCstNm());
            preCreditApplyRequest.setCustomerTypeCode("2");
            preCreditApplyRequest.setSignatureCode(cstCorpBscInfoVO.getLoanCardCd());
            if ("b".equals(cstBscInfoVO.getCertTypCd())){
                if (StringUtils.isNotEmpty(bcCertTypCd)){
                    preCreditApplyRequest.setCertTypeCode(bcCertTypCd);
                }
                if (StringUtils.isNotEmpty(bcCertTypCd) && bcCertTypCd.equals("a")) {
                    preCreditApplyRequest.setOrgCode(bcCertNo);
                }
                if (StringUtils.isNotEmpty(bcCertTypCd) && bcCertTypCd.equals("91")) {
                    preCreditApplyRequest.setUnifiedCreditCode(bcCertNo);
                }
            } else {
                preCreditApplyRequest.setCertTypeCode(cstBscInfoVO.getCertTypCd());
                if ("a".equals(cstBscInfoVO.getCertTypCd())){
                    preCreditApplyRequest.setOrgCode(cstBscInfoVO.getCertNo());
                }
                if (cstBscInfoVO.getCertTypCd().equals("91")) {
                    preCreditApplyRequest.setUnifiedCreditCode(cstBscInfoVO.getCertNo());
                }
            }
            if (StringUtils.isNotEmpty(prjcstAccInfo.getAccNo())){
                preCreditApplyRequest.setBankCardNo(prjcstAccInfo.getAccNo());
            }
            BaseLogUtils.newLogger("=建行对公预授信申请开始=preCreditApplyRequest:{}", JSONObject.toJSONString(preCreditApplyRequest)).info();
            ResponseData<PreCreditApplyResponseDTO> responseData = financialService.preCreditApply(preCreditApplyRequest);
            BaseLogUtils.newLogger("=建行对公预授信申请结束=responseData:{}", JSON.toJSONString(responseData)).info();
            if (null == responseData) {
                dataResultVO.setSuccess(0);
                dataResultVO.setInfo("准入失败，返回结果为空！");
            } else if (!responseData.isSuccess() || !ResponseData.SUCCESS_CODE.equals(responseData.getCode()) || null == responseData.getData()) {
                dataResultVO.setSuccess(0);
                if (StringUtils.isNotEmpty(responseData.getMessage())) {
                    String mes = responseData.getMessage().replaceAll("\n|\r|\t", " ");
                    BaseLogUtils.newLogger("建行准入结果存入：prjId：{},mes：{}", prjId,mes).info();
                    dataResultVO.setInfo(mes);
                }
            } else {
                PreCreditApplyResponseDTO data = responseData.getData();
                if (PreCreditStatusEnum.AUDIT_REJECT.getCode().equals(data.getPreCreditStatus())){
                    dataResultVO.setSuccess(0);
                    if (null != data.getPreCreditDesc()){
                        String s = data.getPreCreditDesc().replaceAll("\n|\r|\t", " ");
                        BaseLogUtils.newLogger("建行准入结果存入：prjId：{},s：{}", prjId,s).info();
                        dataResultVO.setInfo(s);
                    }
                } else if (!PreCreditStatusEnum.AUDIT_REJECT.getCode().equals(data.getPreCreditStatus())){
                    dataResultVO.setSuccess(1);
                }
            }
        } catch (BaseException ex) {
            dataResultVO.setSuccess(BaseConstant.IS_YESNO_NO);
            dataResultVO.setInfo(ex.getMessage());
            BaseLogUtils.newLogger("submitCredit.建行准入校验,prjId:" + prjId + ".ERROR:" + ex.getMessage()).info();
        } catch (Exception e) {
            dataResultVO.setSuccess(BaseConstant.IS_YESNO_NO);
            dataResultVO.setInfo(e.getMessage());
            BaseLogUtils.newLogger("submitCredit.准入失败，系统异常" + e).info();
        } finally {
            BaseLogUtils.newLogger("submitCredit.建行准入,将结果存入").info();
            //4.将准入结果存入prjCstAccInfo
            PrjCstAccInfoVO vo = new PrjCstAccInfoVO();
            if (StringUtils.isNotEmpty(cstAccInfoId)){
                vo.setId(Long.valueOf(cstAccInfoId));
            } else {
                vo.setId(id);
            }
            vo.setAccResCd(String.valueOf(dataResultVO.getSuccess()));
            vo.setAccResMsg(dataResultVO.getInfo());
            boolean modify = prjCstAccInfoService.modify(vo);
            BaseLogUtils.newLogger("submitCredit.建行准入,修改客户账户信息：" + JSON.toJSONString(vo) + "，result：" + modify).info();
        }
        BaseLogUtils.newLogger("submitCredit.建行准入校验返回dataResultVO=" + JSON.toJSONString(dataResultVO)).info();
        return dataResultVO;
    }

    /**
     * 银行信息保存
     */
    @RequestMapping(value = "/savePrjCstAccInfo.do", method = RequestMethod.GET)
    @ResponseBody
    public DataResultVO savePrjCstAccInfo(HttpServletRequest request) throws BaseException {
        BaseLogUtils.newLogger("savePrjCstAccInfo.保存账户信息：" + JSON.toJSONString(request.getParameterMap()) + "，操作人：" + CurrentThreadContext.getCurrentUserName()).info();

        PrjCstAccInfoQueryCondition prjcstAccInfo = getRequestParamForAcc(request);
        String prjId = request.getParameter("prjId");
        String accTypCd = request.getParameter("accTypCd");
        String cstAccInfoId = request.getParameter("cstAccInfoId");//客户账户信息id
        String accNo = request.getParameter("accNo");//银行账户

        DataResultVO dataResultVO = new DataResultVO(BaseConstant.IS_YESNO_YES, "保存成功!");
        PrjCstAccInfoVO infoVO = prjCstAccInfoService.selectById(Long.valueOf(cstAccInfoId));
        BaseLogUtils.newLogger("savePrjCstAccInfo.查询客户账户信息,vo:" + JSONObject.toJSONString(infoVO)).info();
        PrjCstAccInfoVO vo = new PrjCstAccInfoVO();
        vo.setId(Long.valueOf(cstAccInfoId));
        prjcstAccInfo.setId(Long.valueOf(cstAccInfoId));
        try {
            if (StringUtils.isEmpty(accTypCd)) {
                return new DataResultVO(BaseConstant.IS_YESNO_NO, "账户类型为空");
            }
            if (StringUtils.isEmpty(accNo)) {
                return new DataResultVO(BaseConstant.IS_YESNO_NO, "银行账号为空");
            }
            if (StringUtils.isEmpty(cstAccInfoId)) {
                return new DataResultVO(BaseConstant.IS_YESNO_NO, "客户账户信息id为空");
            }

            String chkBinCd = "0";//卡bin结果
            String chkRstCd = "0";//四要素结果
            String rstDesc = null;//四要素结果描述
            //2 当账户类型为个人时，校验卡bin 校验四要素：法人姓名，法人身份证号，银行卡号
            if (accTypCd.equals("0200")) {
                //卡bin
                if (!(BaseConstant.IS_YESNO_YES_STR.equals(infoVO.getChkBinCd()) && StringUtils.isNotEmpty(infoVO.getAccNo()) && accNo.equals(infoVO.getAccNo()))){
                    BaseLogUtils.newLogger("submitCredit.校验银行卡号START,accNo:" + accNo.trim()).info();
                    DataResultDTO dataResultDTO = this.bankCardApiService.searchCardBin(accNo.trim());
                    BaseLogUtils.newLogger("submitCredit.校验银行卡号END,accNo:" + accNo.trim() + ",dataResultDTO" + JSON.toJSONString(dataResultDTO)).info();
                    if (null != dataResultDTO && dataResultDTO.getSuccess() == 1 && null != dataResultDTO.getData()){
                        Object data = dataResultDTO.getData();
                        JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(data));
                        String bankCd = jsonObject.getString("bankCd");
                        String cardType = jsonObject.getString("cardType");
                        if ("CCB".equals(bankCd) && BaseConstant.IS_YESNO_NO_STR.equals(cardType)){
                            chkBinCd = "1";
                        }
                    }
                } else {
                    chkBinCd = "1";
                }
                //四要素
                DataResultVO resultVO = prjCstAccInfoService.snVerifyModifyPrjAccInfo(prjcstAccInfo);
                BaseLogUtils.newLogger("submitCredit.校验四要素END,prjcstAccInfo:" + JSONObject.toJSONString(prjcstAccInfo) + ",dataResultVO" + JSON.toJSONString(resultVO)).info();
                if (BaseConstant.IS_YESNO_YES == resultVO.getSuccess() && null != resultVO.getData()) {
                    Map<String, String> resultMap = (Map<String, String>) resultVO.getData();
                    chkRstCd = resultMap.get("chkRstCd");
                    rstDesc = resultMap.get("rstDesc");
                }
                //将卡bin校验结果及四要素校验结果存入
                vo.setChkBinCd(chkBinCd);
                vo.setChkRstCd(chkRstCd);
                vo.setRstDesc(rstDesc);
            } else {
                vo.setChkBinCd("0");
                vo.setChkRstCd("0");
                vo.setRstDesc("对公账户无需校验四要素");
            }
            vo.setMp(prjcstAccInfo.getMp());
            vo.setBkCd("01");
            vo.setBkNm("建设银行");
            vo.setAccNo(accNo.trim());
            vo.setAccTypCd(accTypCd);
            boolean modify1 = prjCstAccInfoService.modify(vo);
            BaseLogUtils.newLogger("savePrjCstAccInfo.修改建行对公账户数据vo=" + JSON.toJSONString(vo) + "response:" + modify1).info();

            if (accTypCd.equals("0200") &&chkBinCd.equals("0")){
                dataResultVO.setSuccess(0);
                dataResultVO.setInfo("卡bin校验失败，需为建行借记卡，请核实！");
                return dataResultVO;
            }
            if (accTypCd.equals("0200") &&chkRstCd.equals("0")){
                dataResultVO.setSuccess(0);
                dataResultVO.setInfo("四要素校验失败，原因：" + rstDesc);
                return dataResultVO;
            }
        } catch (BaseException ex) {
            dataResultVO.setSuccess(BaseConstant.IS_YESNO_NO);
            dataResultVO.setInfo(ex.getMessage());
            BaseLogUtils.newLogger("savePrjCstAccInfo.建行信息采集校验,prjId:" + prjId + ".ERROR:" + ex.getMessage()).info();
        } catch (Exception e) {
            BaseLogUtils.newLogger("savePrjCstAccInfo.保存失败，系统异常" + e).info();
            return new DataResultVO(BaseConstant.IS_YESNO_NO, "保存失败，系统异常");
        }
        BaseLogUtils.newLogger("savePrjCstAccInfo.建行信息采集返回dataResultVO=" + JSON.toJSONString(dataResultVO)).info();
        return dataResultVO;
    }

    private PrjCstAccInfoQueryCondition getRequestParamForAcc(HttpServletRequest request){
        BaseLogUtils.newLogger("获取页面信息：" + JSON.toJSONString(request.getParameterMap()) + "，操作人：" + CurrentThreadContext.getCurrentUserName()).info();

        String prjId = request.getParameter("prjId");//项目id
        String cstId = request.getParameter("cstId");//客户id --- 此为法人项目
        String cstNm = request.getParameter("cstNm");//客户名称 --- 公司名称
        String mNm = request.getParameter("mNm");//法人名称
        String mCertNo = request.getParameter("mCertNo");//法人身份证号
        String fundRasInsId = request.getParameter("fundRasInsId");//机构id
        String fundRasInsNm = request.getParameter("fundRasInsNm");//机构名称
        String insCode = request.getParameter("insCode");//机构code
        String accNo = request.getParameter("accNo");//银行账户

        if (StringUtils.isEmpty(prjId)) {
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "项目ID不能为空！");
        }
        if (StringUtils.isEmpty(cstId)) {
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "客户ID不能为空！");
        }
        if (StringUtils.isEmpty(cstNm)) {
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "企业名称不能为空！");
        }
        if (StringUtils.isEmpty(mNm)) {
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "法人名称不能为空！");
        }
        if (StringUtils.isEmpty(mCertNo)) {
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "法人证件号不能为空！");
        }
        if (StringUtils.isEmpty(fundRasInsId)) {
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "机构id不能为空！");
        }
        if (StringUtils.isEmpty(insCode)) {
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "机构code不能为空！");
        }
        PrjCstAccInfoQueryCondition condition = new PrjCstAccInfoQueryCondition();
        condition.setPrjId(Long.valueOf(prjId));
        condition.setCstId(Long.valueOf(cstId));
        condition.setInsCode(insCode);
        condition.setInsId(Long.valueOf(fundRasInsId));
        if (StringUtils.isNotEmpty(accNo)){
            condition.setAccNo(accNo);
        }
        condition.setCertNo(mCertNo);
        condition.setCstNm(mNm);
        condition.setBkCd("01");
        condition.setBkNm("建设银行");
        condition.setCertTypCd(DictionaryConstant.CODE_CERT_TYP_CD_0);
        CstBscInfoVO cstBscInfoVO = cstBscInfoService.selectDetailById(Long.valueOf(cstId));
        BaseLogUtils.newLogger("查询客户信息：" + JSON.toJSONString(cstBscInfoVO)).info();
        if (null != cstBscInfoVO.getCstCorpBscInfoVO().getCstCorpTeamVO().getMp1()){
            condition.setMp(cstBscInfoVO.getCstCorpBscInfoVO().getCstCorpTeamVO().getMp1());
        }
        return condition;
    }


}
